using Godot;
using System;
using System.Collections.Generic;
using System.IO;
using Common;
namespace Library {
	public class MusicController : Node2D {
		static MusicController() {
			Collection = new JsonFile<Dictionary<string, Data>>("res://Audio/Music/Collections.json").Source;
		}

		public struct Data {
			public string File { get; set; }
			public float LoopStart { get; set; }
			public float LoopEnd { get; set; }
		}

		public const int PlayerSlotNumber = 6;
		readonly List<MusicPlayer> players = new List<MusicPlayer>();
		public static Dictionary<string, Data> Collection { get; private set; }

		public override void _Ready() {
			for (int i = 0; i < PlayerSlotNumber; i += 1) {
				MusicPlayer player=GetNode<MusicPlayer>(i.ToString());
				players.Add(player);
			}
		}
		public bool IsSlotValid(int slot) => (slot >= 0 && slot < PlayerSlotNumber);
		public MusicPlayer GetPlayer(int slot) {
			if (!IsSlotValid(slot)) {
				return null;
			}
			return players[slot];
		}
		public MusicPlayer this[int slot] => GetPlayer(slot);
	}
}
